#include <Arduino.h>
#include "Button.h"
#include "WatchDog.h"
#include "Wifi_Ctrl.h"
#include "Menu_Ctrl.h"
#include "Aliyun.h"
#include "Ze08Ch2o.h"
#include "Led.h"

void setup() 
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  delay(10);

  Serial.printf("ESP32 HEAP %d\r\n", esp_get_free_heap_size());

  WiFi_Setup();

  Serial.printf("ESP32 HEAP %d\r\n", esp_get_free_heap_size());

  Button_Init();

  Serial.printf("ESP32 HEAP %d\r\n", esp_get_free_heap_size());

  Ze08_Ch2o_Init();

  Serial.printf("ESP32 HEAP %d\r\n", esp_get_free_heap_size());

  Led_Init();

  Serial.printf("ESP32 HEAP %d\r\n", esp_get_free_heap_size());

  delay(1000);

  WatchDog_Init();

  Serial.println("loop start");
}

void loop() 
{
  // put your main code here, to run repeatedly:
  Feed_Dog();

  uint8_t button_state = Get_Button_State();
  if(button_state != 0)
  {
    Serial.printf("Button ESP32 HEAP1 %d\r\n", esp_get_free_heap_size());
    Serial.printf("button %d\r\n", button_state);
  }

  menu_proc(button_state);

  WiFi_Loop();

  //client.loop();
  Aliyun_Loop();

  Read_Ze08_Ch2o_Data();

  Feed_Dog();
}